//
//  MOCommonUseViewCell.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/6/7.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MOCommonUseViewCell.h"

#define itemWidth SCREEN_WIDTH/3

@interface MOCommonUseViewCell ()

@property(nonatomic,strong)UIImageView *iconImageView;

@property(nonatomic,strong)UILabel *nameLabel;

//添加
@property(nonatomic,strong)UIImageView *addImageView;
//删除
@property(nonatomic,strong)UIImageView *deleteImageView;
//数量
@property(nonatomic,strong)UILabel *numberLabel;

@property(nonatomic,strong)UIView *line1;


@end

@implementation MOCommonUseViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        [self creatView];
    }
    return self;
}

-(void)creatView
{
    self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kWConversions(50), kWConversions(50))];
    self.iconImageView.centerX = itemWidth/2;
    self.iconImageView.centerY = itemWidth/2-15;
    self.iconImageView.layer.masksToBounds = YES;
    self.iconImageView.layer.cornerRadius = 11.0;
//    self.iconImageView.backgroundColor = KGrayColor_ededed;
    [self addSubview:self.iconImageView];
    
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.iconImageView.bottom+10, itemWidth, 15)];
    self.nameLabel.textColor = KBlackColor_2A2A2A;
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    self.nameLabel.font = [UIFont boldSystemFontOfSize:12];
    [self addSubview:self.nameLabel];
    
    self.addImageView = [[UIImageView alloc]initWithFrame:CGRectMake(itemWidth-kWConversions(17)-13, 13, kWConversions(17), kWConversions(17))];
    self.addImageView.userInteractionEnabled = YES;
    self.addImageView.image = IMAGE(@"use_add_back");
    [self addSubview:self.addImageView];
    
    self.deleteImageView = [[UIImageView alloc]initWithFrame:CGRectMake(itemWidth-kWConversions(17)-13, 13, kWConversions(17), kWConversions(17))];
    self.deleteImageView.userInteractionEnabled = YES;
    self.deleteImageView.image = IMAGE(@"use_delete");
    [self addSubview:self.deleteImageView];
    
    self.numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMinY(self.iconImageView.frame)-kHConversions(3), 1, kWConversions(17))];
    self.numberLabel.backgroundColor = KRedColor_F53838;
    self.numberLabel.textColor = KWhiteColor;
    self.numberLabel.font = [UIFont boldSystemFontOfSize:11];
    self.numberLabel.layer.masksToBounds = YES;
    self.numberLabel.layer.cornerRadius = kWConversions(17)/2;
    self.numberLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.numberLabel];
    
    
    self.line1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, itemWidth, 1)];
    self.line1.backgroundColor = KGrayColor_ededed;
    [self addSubview:self.line1];
    
    UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(0, itemWidth-1, itemWidth, 1)];
    line2.backgroundColor = KGrayColor_ededed;
    [self addSubview:line2];
    
    UIView *line3 = [[UIView alloc]initWithFrame:CGRectMake(itemWidth-1, 0, 1, itemWidth)];
    line3.backgroundColor = KGrayColor_ededed;
    [self addSubview:line3];
    
}

-(void)setModel:(MOCommonUseModel *)model
{
    /*
     * 类型
     * 0.普通 1.删除 2.添加 3.数量
     */
    if ([model.typeStr integerValue]==0) {
        self.addImageView.hidden = YES;
        self.deleteImageView.hidden = YES;
        self.numberLabel.hidden = YES;
    }else if ([model.typeStr integerValue]==1) {
        self.addImageView.hidden = YES;
        self.deleteImageView.hidden = NO;
        self.numberLabel.hidden = YES;
    }else if ([model.typeStr integerValue]==2) {
        self.addImageView.hidden = NO;
        self.deleteImageView.hidden = YES;
        self.numberLabel.hidden = YES;
    }else if ([model.typeStr integerValue]==3){
        self.addImageView.hidden = YES;
        self.deleteImageView.hidden = YES;
        self.numberLabel.hidden = NO;
        CGFloat width = [NSString labelAutoCalculateRectWith:model.countStr WithFont:[UIFont boldSystemFontOfSize:11] MaxSize:CGSizeMake(100, kWConversions(17))].width+8;
        if (width<kWConversions(17)) {
            width = kWConversions(17);
        }
        self.numberLabel.width = width;
        self.numberLabel.x = CGRectGetMaxX(self.iconImageView.frame)-width/2;
        self.numberLabel.text = model.countStr;
        
        if ([model.countStr integerValue]>0) {
            self.numberLabel.hidden = NO;
        }else{
            self.numberLabel.hidden = YES;
        }
    }
    
    self.iconImageView.image = IMAGE(model.imageStr);
    self.nameLabel.text = model.nameStr;
    if (model.itemIndex>2) {
        self.line1.hidden = YES;
    }else{
        self.line1.hidden = NO;
    }
}



@end
